package com.pucong.gitee.database.backup.business.unRelational.redis.controller;

import com.alibaba.fastjson.JSON;
import com.pucong.gitee.database.backup.business.unRelational.redis.service.InfoSinglesService;
import com.pucong.gitee.database.backup.business.unRelational.redis.util.ClusterRelation;
import com.pucong.gitee.database.backup.common.entity.redis.RedisInfo;
import com.pucong.gitee.database.backup.common.entity.redis.vo.RedisGetKeyInfo;
import com.pucong.gitee.database.backup.common.entity.redis.vo.RedisNetInfo;
import com.pucong.gitee.database.backup.utils.RedisUtil;
import com.pucong.gitee.database.backup.utils.Res;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.util.Slowlog;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/auto/redis/infoSingles")
public class InfoSinglesController {

    @Autowired
    private InfoSinglesService infoSinglesService;

    /**
     * 获取基础服务信息
     */
    @GetMapping("/getBaseInfo/{id}")
    public Res<RedisInfo> getBaseInfo(@ApiParam("主键") @PathVariable("id") String id) {
        RedisInfo redisInfo = infoSinglesService.getBaseInfo(id);
        return Res.ok(redisInfo);
    }


    /**
     * 获取服务日志信息
     */
    @GetMapping("/getLogsInfo/{id}")
    public Res<List<Slowlog>> getNodeInfo(@ApiParam("主键") @PathVariable("id") String id) {
        List<Slowlog> slowlogList = infoSinglesService.getLogsInfo(id);
        return Res.ok(slowlogList);
    }


    /**
     * 监控服务内存信息
     */
    @GetMapping("/getMemInfo/{id}")
    public Res<RedisNetInfo> getMemInfo(@ApiParam("主键") @PathVariable("id") String id) {
        RedisNetInfo redisNetInfo = infoSinglesService.getMemInfo(id);
        return Res.ok(redisNetInfo);
    }


    /**
     * 监控服务处理器信息
     */
    @GetMapping("/getCpuInfo/{id}")
    public Res<RedisNetInfo> getCpuInfo(@ApiParam("主键") @PathVariable("id") String id) {
        RedisNetInfo redisNetInfo = infoSinglesService.getCpuInfo(id);
        return Res.ok(redisNetInfo);
    }

    /**
     * 监控服务数据库信息
     */
    @GetMapping("/getKeyInfo/{id}")
    public Res<Long[]> getKeyInfo(@ApiParam("主键") @PathVariable("id") String id) {
        Long[] longs = infoSinglesService.getKeyInfo(id);
        return Res.ok(longs);
    }

    /**
     * 监控服务网络信息
     */
    @GetMapping("/getNetInfo/{id}")
    public Res<RedisNetInfo> getNetInfo(@ApiParam("主键") @PathVariable("id") String id) {
        RedisNetInfo redisNetInfo = infoSinglesService.getNetInfo(id);
        return Res.ok(redisNetInfo);
    }
}

